home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / rm_om.zip / ASKREPLY.C < prev    next >
C/C++ Source or Header  |  1991-10-16  |  993b  |  61 lines

  1. /*
  2. **    Ask the user for a yes/no/quit/all answer, depending on default
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <sgtty.h>
  7. #include    "ascii.h"
  8. #include    "askreply.h"
  9.  
  10. int askreply(assume)
  11. int assume;    {
  12.  
  13. redo:    switch(readchar())    {
  14.     case 'y':
  15.     case 'Y':
  16. yes:        printf("Yes\n");
  17.         return YES;
  18.     case 'n':
  19.     case 'N':
  20. no:        printf("No\n");
  21.         return NO;
  22.     case 'x':
  23.     case 'X':
  24.     case 'q':
  25.     case 'Q':
  26.     case SUB:
  27.     case ESC:
  28.     case EOF:
  29. quit:        printf("Quit\n");
  30.         return QUIT;
  31.     case 'a':
  32.     case 'A':
  33. all:        printf("All\n");
  34.         return ALL;
  35.     default:
  36.         if(assume==YES)        goto yes;
  37.         if(assume==NO)        goto no;
  38.         if(assume==QUIT)    goto quit;
  39.         if(assume==ALL)        goto all;
  40.         putchar('\7');
  41.         goto redo;
  42.     }
  43. }
  44.  
  45.  
  46. int readchar()    {
  47.     if(isatty(fileno(stdin)))    {
  48.         register int c;
  49.         struct sgttyb arg;
  50.  
  51.         ioctl(1,TIOCGETP,&arg);
  52.         arg.sg_flags|=RAW;
  53.         ioctl(1,TIOCSETP,&arg);
  54.         c=getc(stdin);
  55.         arg.sg_flags^=RAW;
  56.         ioctl(1,TIOCSETP,&arg);
  57.         return(c);
  58.     }
  59.     return agetc(stdin);
  60. }
  61.